package com.it2297.view;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JTable;

import com.it2297.controller.CustomerController;
import com.it2297.controller.NeedyController;

public class SearchCustomerView extends JPanel {
	private final CustomerController scv = new CustomerController(this);

	private final JLabel lblSearchCustomer = new JLabel(
			"Search Customer's Information");
	private final JLabel lblIdentificationNumber = new JLabel("Username (NRIC)");
	private final JTextField nric_TF = new JTextField();
	private final JButton btnSearch = new JButton("Search");
	private final JTextField name_TF = new JTextField();
	private final JLabel lblName = new JLabel("Name");
	private final JLabel lblNewLabel = new JLabel("Email");
	private final JTextField email_TF = new JTextField();
	private final JLabel lblAddress = new JLabel("Address");
	private final JTextField address_TF = new JTextField();
	private final JTextField gender_TF = new JTextField();
	private final JLabel lblGender = new JLabel("Gender");
	private final JLabel lblRace = new JLabel("Race");
	private final JTextField phone_TF = new JTextField();
	private final JLabel lblDateOfBirth = new JLabel("Date Of Birth");
	private final JTextField race_TF = new JTextField();
	private final JLabel lblContactNumber = new JLabel("Contact Number");
	private final JLabel lblCountryOfBirth = new JLabel("Country of Birth");
	private final JTextField dob_TF = new JTextField();
	private final JTextField cob_TF = new JTextField();

	/**
	 * Create the panel.
	 */
	public SearchCustomerView() {
		cob_TF.setFont(new Font("Arial", Font.PLAIN, 12));
		cob_TF.setEditable(false);
		cob_TF.setBounds(237, 561, 86, 23);
		cob_TF.setColumns(10);
		dob_TF.setEditable(false);
		dob_TF.setFont(new Font("Arial", Font.PLAIN, 12));
		dob_TF.setBounds(237, 505, 157, 23);
		dob_TF.setColumns(10);
		race_TF.setFont(new Font("Arial", Font.PLAIN, 12));
		race_TF.setEditable(false);
		race_TF.setBounds(237, 448, 58, 22);
		race_TF.setColumns(10);
		phone_TF.setEditable(false);
		phone_TF.setFont(new Font("Arial", Font.PLAIN, 12));
		phone_TF.setBounds(237, 330, 140, 23);
		phone_TF.setColumns(10);
		gender_TF.setFont(new Font("Arial", Font.PLAIN, 12));
		gender_TF.setEditable(false);
		gender_TF.setBounds(237, 390, 98, 23);
		gender_TF.setColumns(10);
		address_TF.setEditable(false);
		address_TF.setBounds(237, 232, 296, 61);
		address_TF.setColumns(10);
		email_TF.setEditable(false);
		email_TF.setBounds(237, 177, 190, 23);
		email_TF.setColumns(10);
		name_TF.setEditable(false);
		name_TF.setFont(new Font("Arial", Font.PLAIN, 12));
		name_TF.setBounds(237, 123, 157, 23);
		name_TF.setColumns(10);
		nric_TF.setBounds(188, 84, 173, 20);
		nric_TF.setColumns(10);

		initGUI();
	}

	private void initGUI() {
		setLayout(null);
		lblSearchCustomer.setFont(new Font("Arial", Font.BOLD, 15));
		lblSearchCustomer.setBounds(37, 28, 224, 33);

		add(lblSearchCustomer);
		lblIdentificationNumber.setFont(new Font("Arial", Font.PLAIN, 12));
		lblIdentificationNumber.setBounds(37, 72, 140, 42);

		add(lblIdentificationNumber);

		add(nric_TF);
		btnSearch.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				if (nric_TF.getText().equals("")) {
					JOptionPane.showMessageDialog(null,
							"Please enter a valid username (nric).");
				} else {

					
					
						scv.search();
					if(dob_TF.getText()==null){
						dob_TF.setText("");
					}
				}
			}
		});
		btnSearch.setFont(new Font("Arial", Font.PLAIN, 12));
		btnSearch.setBounds(444, 82, 89, 23);

		add(btnSearch);

		add(name_TF);
		lblName.setFont(new Font("Arial", Font.PLAIN, 12));
		lblName.setBounds(127, 125, 46, 18);

		add(lblName);
		lblNewLabel.setFont(new Font("Arial", Font.PLAIN, 12));
		lblNewLabel.setBounds(127, 180, 46, 20);

		add(lblNewLabel);

		add(email_TF);
		lblAddress.setFont(new Font("Arial", Font.PLAIN, 12));
		lblAddress.setBounds(127, 232, 75, 23);

		add(lblAddress);

		add(address_TF);

		add(gender_TF);
		lblGender.setFont(new Font("Arial", Font.PLAIN, 12));
		lblGender.setBounds(127, 396, 46, 17);

		add(lblGender);
		lblRace.setFont(new Font("Arial", Font.PLAIN, 12));
		lblRace.setBounds(127, 448, 46, 20);

		add(lblRace);

		add(phone_TF);
		lblDateOfBirth.setFont(new Font("Arial", Font.PLAIN, 12));
		lblDateOfBirth.setBounds(127, 505, 89, 23);

		add(lblDateOfBirth);

		add(race_TF);
		lblContactNumber.setFont(new Font("Arial", Font.PLAIN, 12));
		lblContactNumber.setBounds(127, 330, 101, 23);

		add(lblContactNumber);
		lblCountryOfBirth.setFont(new Font("Arial", Font.PLAIN, 12));
		lblCountryOfBirth.setBounds(127, 561, 115, 23);

		add(lblCountryOfBirth);

		add(dob_TF);

		add(cob_TF);
	}

	public String getNric() {
		return nric_TF.getText();
	}

	public void setName(String name) {
		name_TF.setText(name);
	}

	public void setEmail(String email) {
		email_TF.setText(email);
	}

	public void setAddress(String address) {
		address_TF.setText(address);
	}

	public void setPhone(String phone) {
		phone_TF.setText(phone);
	}

	public void setGender(String gender) {
		gender_TF.setText(gender);
	}

	public void setRace(String race) {
		race_TF.setText(race);
	}

	public void setDOB(Date dob) {
		DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
		String reportDate = df.format(dob);
		dob_TF.setText(reportDate);
	}

	public void setCOB(String cob) {
		cob_TF.setText(cob);
	}
	
	public void setDate(){
		dob_TF.setText("");
	}
}
